function switchVisibility(targetObjectId,eventObj,cordX,cordY){
	if(eventObj){
		var eventTarget = eventObj.target?eventObj.target:eventObj.srcElement;
		if(window.currentlyPopupTarget!=eventTarget){
			hideCurrentPopup();
			window.currentlyPopupTarget = eventTarget;
		}
		var styleObject = getStyleObject(targetObjectId),object = getObject(targetObjectId);
		if(!object.shim) object.shim = new iframeShim(object);
		if(styleObject){
			// stop event from bubbling up any farther
			eventObj.cancelBubble = true;
			if(styleObject.visibility=='visible') hideCurrentPopup();
			else showPopup(targetObjectId,eventObj,cordX,cordY)
		}
		else return false;
	}
	else{// there was no event object, so we won't be able to position anything, so give up
		return false;
	}
}

function showPopup(targetObjectId,eventObj,cordX,cordY){
	if(eventObj){
		// stop event from bubbling up any farther
		eventObj.cancelBubble = true;
		
		var eventTarget = eventObj.target?eventObj.target:eventObj.srcElement;
		if(window.currentlyPopupTarget!=eventTarget){
			hideCurrentPopup();
			window.currentlyPopupTarget = eventTarget;
		}
		
		if(window.currentlyVisiblePopup == targetObjectId) return;
		
		var object = getObject(targetObjectId);
		if(!object.shim) object.shim = new iframeShim(object);
		
		stopTimeG();
		
		// hide any currently-visible popups
		hideCurrentPopup();
		// and position it & make it visible
		if(positionObject(targetObjectId,cordX,cordY)){
	    	changeObjectVisibility(targetObjectId,'visible');
			// if we successfully showed the popup , store its Id on a globally-accessible object
	    	window.currentlyVisiblePopup = targetObjectId;
	    	return true;
		}
		else{// we couldn't show the popup, boo hoo!
	    	return false;
		}
    }
	else{// there was no event object, so we won't be able to position anything, so give up
		return false;
    }
}

function hideCurrentPopup(){
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.flagHideCurPopup) return;//IE bodyDivMask bug
	if(window.currentlyVisiblePopup){
		changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
		moveObject(window.currentlyVisiblePopup,0,0);
		window.currentlyVisiblePopup = false;
    }
}

// setup an event handler to hide popups for generic clicks on the document
myAttachEvent(document,'click',hideCurrentPopup)

function positionObject(objectId,x,y){
	// get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId),object = getObject(objectId);
	if(!object.shim) object.shim = new iframeShim(object);
	if(styleObject){
		var topY=0,leftX=0;
		var winWH = getWindowWH();
		var windowHeight = winWH.h,windowWidth = winWH.w;
		var objectHeight = object.offsetHeight,objectWidth = object.offsetWidth;
		// note: If you use a DOCTYPE that puts Explorer 6 in standards compliant mode, some properties of document.body are reassigned to document.documentElement. eg scrollTop,scrollLeft
		var scrollTop = document.documentElement.scrollTop||document.body.scrollTop,scrollLeft = document.documentElement.scrollLeft||document.body.scrollLeft;
		if(objectWidth>windowWidth){
			leftX = 0 + scrollLeft;
		}
		else if(typeof x!='undefined' && x!=null && x!=''){
			if(x+objectWidth>windowWidth+scrollLeft){// overflow
				leftX = windowWidth-objectWidth+scrollLeft;
				leftX = leftX<0?0:leftX;
			}
			else leftX = x;//+scrollLeft
		}
		else{// popup from center
			leftX = (windowWidth-objectWidth)/2+scrollLeft;
		}
		if(objectHeight>windowHeight){
			topY = 0 + scrollTop;
		}
		else if(typeof y!='undefined' && y!=null && y!=''){
			if(y+objectHeight>windowHeight+scrollTop){// overflow
				topY = windowHeight-objectHeight+scrollTop;
				topY = topY<0?0:topY;
			}
			else topY = y;//+scrollTop
		}
		else{// popup from center
			topY = (windowHeight-objectHeight)/2+scrollTop;
		}
		return moveObject(objectId,leftX,topY);
	}
	else{// we couldn't find the object, so we can't position

		return false;
	}
}


// ************************
// *** utility routines ***
// ************************
function getObject(objectId){// cross-browser function to get an object given its id
    if(document.getElementById && document.getElementById(objectId)){
		// W3C DOM
		return document.getElementById(objectId);
    }
	else if(document.all && document.all(objectId)){
		// MSIE 4 DOM
		return document.all(objectId);
    }
	else if(document.layers && document.layers[objectId]){
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    }
	else return false;
}

function getStyleObject(objectId){// cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)){
		// W3C DOM
		return document.getElementById(objectId).style;
    }
	else if(document.all && document.all(objectId)){
		// MSIE 4 DOM
		return document.all(objectId).style;
    }
	else if(document.layers && document.layers[objectId]){
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    }
	else return false;
}

/* Turn javaScriptProperties into java-script-properties, useful for CSS stuff*/
function dashify(str){
    return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
}
function getCurrentStyle(element,styleProp){//read only
    var retVal;
    if(element.currentStyle){
       //IE
       retVal = element.currentStyle[styleProp];
    }
	else if(document.defaultView && document.defaultView.getComputedStyle){
       //Mozilla
       retVal = document.defaultView.getComputedStyle(element,null).getPropertyValue(dashify(styleProp));
    }
	else{
       //Safari :(
       retVal = null;
    }
    return retVal;
}

function getLocalOffset(offset,direction){//direction: Top Left
	var y = offset['offset' + direction];
    var div;
    try{
        div = offset.offsetParent;
    }
	catch(ex){
        //with dhtml actions that change DOM IE may throw unspecified error when checking offsetParent property
        return y;
    }
    while(div && getCurrentStyle(div, 'position') == 'static'){
        y += div['offset' + direction];
        try{
            div = div.offsetParent;
        }
		catch(ex){
            // with dhtml actions that change DOM IE may throw unspecified error when checking offsetParent property
            return y;
        }
    }
    return y;
}
function getLocalOffsetTop(offset){
	return getLocalOffset(offset,'Top');
}
function getLocalOffsetLeft(offset){
    return getLocalOffset(offset,'Left');
}

function getXY(object){// function to get an object's absolute position : x & y
    var pt = new Point(0,0);
	pt.x = getLocalOffsetLeft(object);
	pt.y = getLocalOffsetTop(object);
    return pt;
}
function Point(iX, iY){
	this.x = iX;
	this.y = iY;
}

function iframeShim(theDiv){
    this.div = theDiv;
    if (this.div.currentStyle) {
        if (navigator.userAgent.indexOf("MSIE 7") != -1) {
            // IE7, no need for shim, but have to use IE opacity filter
            this.setStyle = this.setStyleNonIE;
            this.setOpacity = this.setOpacityIE;
            this.getOpacity = this.getOpacityIE;
        } else {
            // We only need this in IE6
            var frame = document.createElement("iframe");
            frame.src = "javascript:''"
            frame.frameBorder = "0";
            frame.scrolling = "no";
            frame.className = "iframeShim";
            frame.style.zIndex = this.div.currentStyle.zIndex - 1;
            var offsetLeft = getLocalOffsetLeft(this.div);
            var styleLeft = this.div.currentStyle.left;
            if (offsetLeft == 0 && styleLeft){
                frame.style.left = styleLeft;
            } else {
              	frame.style.left = offsetLeft;
        	}
            var offsetTop = getLocalOffsetTop(this.div)
            var styleTop = this.div.currentStyle.top;
            var styleBottom = this.div.currentStyle.bottom;
            if (offsetTop == 0 && (styleTop || styleBottom)){
            frame.style.top = styleTop;
                frame.style.bottom = styleBottom;
            } else {
	           frame.style.top = offsetTop;
        	}
            frame.style.height = this.div.offsetHeight;
            frame.style.position = "absolute";
            frame.style.display = this.div.currentStyle.display;
			frame.style.visibility = this.div.currentStyle.visibility;
            this.iframe = frame;
            this.div.parentNode.insertBefore(this.iframe, this.div);
			
            this.setStyle = this.setStyleIE;
            this.setOpacity = this.setOpacityIE;
            this.getOpacity = this.getOpacityIE;
        }
    } else {
        //Non IE, just pass calls through
        this.setStyle = this.setStyleNonIE;
        this.setOpacity = this.setOpacityNonIE;
        this.getOpacity = this.getOpacityNonIE;
    }
}
iframeShim.prototype = {
    setStyleNonIE : function(prop, val){
                        this.div.style[prop] = val;
                    },

    setStyleIE : function(prop, val){
                        this.div.style[prop] = val;
                        if (prop != 'position'){
                        	//Iframe must remain position:absolute
	                        this.iframe.style[prop] = val;
                        }
                        //Refresh iframe's width and height from the browser calculated offsets.
                        this.iframe.style.width = this.div.offsetWidth + "px";
	                    this.iframe.style.height = this.div.offsetHeight + "px";
	                    this.iframe.style.left = getLocalOffsetLeft(this.div);
				        this.iframe.style.top = getLocalOffsetTop(this.div);

                 },

    setOpacityNonIE : function(val){
                            if (val < 0) val = 0;
                            if (val > 1) val = 1;
                            this.div.style.opacity = val;
                      },

    setOpacityIE : function(val){
                        if (val < 0) val = 0;
                        if (val > 1) val = 1;
                        this.div.filters.alpha.opacity = (val * 100);
                        //Iframe stays at opacity 0
                   },

    getOpacityNonIE : function() { return getCurrentStyle(this.div, 'opacity'); },
    getOpacityIE : function() { return this.div.filters.alpha.opacity / 100.0; },

    getStyle : function(prop) {
        return this.div.style[prop];
    }

}

function changeObjectVisibility(objectId,newVisibility){
	// get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId),object = getObject(objectId);
	if(!object.shim) object.shim = new iframeShim(object);
    if(styleObject){
		if(typeof popupDivUseFilter!='undefined' && popupDivUseFilter){
			if(typeof styleObject.filter!='undefined'){
				styleObject.filter=(typeof popupDivFilterType=='string')?popupDivFilterType:'blendTrans(duration=0.2)';
				object.filters[0].Apply();
				object.shim.setStyle('visibility',newVisibility);
				object.filters[0].Play();
			}
			else if(typeof styleObject.MozOpacity!='undefined'){
				styleObject.visibility = 'visible';
				if(newVisibility=='visible'){
					object.from = 0.0;
					object.to = 1.0;
					styleObject.MozOpacity = object.from;
				}
				else{
					object.from = 1.0;
					object.to = 0.0;
					styleObject.MozOpacity = object.from;
				}
				object.duration = 500;
				object.startTime = (new Date).getTime() - 13;
				if(object.timer!=null){
					clearInterval(object.timer);
					object.timer=null;
				}
				object.timer = setInterval('blendTrans4Gecko("'+newVisibility+'","'+objectId+'")',13);
			}
			else object.shim.setStyle('visibility',newVisibility);
		}
		else object.shim.setStyle('visibility',newVisibility);
		return true;
    }
	else{// we couldn't find the object, so we can't change its visibility
		return false;
    }
}

function moveObject(objectId,newXCoordinate,newYCoordinate){
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId),object = getObject(objectId);
	if(!object.shim) object.shim = new iframeShim(object);
    if(styleObject){
		object.shim.setStyle('left',newXCoordinate+'px');
		object.shim.setStyle('top',newYCoordinate+'px');
		return true;
    }
	else {// we couldn't find the object, so we can't very well move it
		return false;
    }
}

function myAttachEvent(d,e,f){
	try {
		if(d.attachEvent) d.attachEvent("on"+e,f);
		else if(d.addEventListener) d.addEventListener(e,f,false);
		else{
			var oldF = eval('d.on'+e);
			if(typeof oldF!='function') eval('d.on'+e+'=f');
			else eval('d.on'+e)=function(){oldF();f();}
		}
	}
	catch (error){}
}


/*
 * function of filter:blendTrans(IE) 4 Gecko
 */
function blendTrans4Gecko(newVisibility,objId){
	var styleObject = getStyleObject(objId),object = getObject(objId);
	var T,ease,time = (new Date).getTime();
	
	T = sp_clampTo(time-object.startTime,0,object.duration);
	if (T >= object.duration) {
		clearInterval(object.timer);
		object.timer = null;
		styleObject.visibility = newVisibility;
	}
	else {
		ease = 0.5 - (0.5 * Math.cos(Math.PI * T / object.duration));
		object.now = sp_computeNextFloat (object.from, object.to, ease);
		if(styleObject.MozOpacity) styleObject.MozOpacity = object.now < 1 ? object.now : 0.99;
	}
}

function sp_clampTo(value, min, max){ // constrains a value between two limits
	return value < min ? min : value > max ? max : value;
}

function sp_computeNextFloat(from, to, ease){ // self explaining
	return from + (to - from) * ease;
}


//utility 4 onmouseover & onmouseout
var timeID = null;
function stopTimeG(){
	if(timeID!=null){clearTimeout(timeID);timeID = null;}
}

function startTimeG(){
	if(timeID==null) timeID = setTimeout('hideCurrentPopup()',100);
}



function softScroll(id,iter,time){
	var des = document.getElementById(id)||null;
	if(des!=null){
		des.pointerDes = {x:getLocalOffset(des,'Left'),y:getLocalOffset(des,'Top')-20};
		des.pointerStart = {x:document.documentElement.scrollLeft||document.body.scrollLeft,y:document.documentElement.scrollTop||document.body.scrollTop};
		des.scrollSpan = {x:des.pointerDes.x-des.pointerStart.x,y:des.pointerDes.y-des.pointerStart.y};
		des.AnyIter = iter;
		des.AnyTime = time;
		des.curIter = 0;
		des.timer = null;
		fnSoftScrollStart(des);
	}
}
function fnSoftScrollStart(des){
			if(des.timer!=null){
				clearTimeout(des.timer);
				des.timer = null;
			}
			if(des.curIter>=0&&des.curIter<=des.AnyIter){
				var per = des.curIter*(95/des.AnyIter)+5;
				var x = des.pointerStart.x+des.scrollSpan.x*per/100;
				var y = des.pointerStart.y+des.scrollSpan.y*per/100;
				window.scrollTo(x,y);
				des.curIter += 1;
				if(des.curIter<0 || des.curIter>des.AnyIter){
					window.scrollTo(des.pointerDes.x,des.pointerDes.y);
				}
				else des.timer = setTimeout(function(){fnSoftScrollStart(des)},des.AnyTime);
			}
		}
		
function getWindowWH(){
	var pointer = {w:0,h:0};
  	if(typeof(window.innerWidth)=='number'){//Non-IE
    	pointer.w = window.innerWidth;
    	pointer.h = window.innerHeight;
  	}
	else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){//IE 6+ in 'standards compliant mode'
    	pointer.w = document.documentElement.clientWidth;
    	pointer.h = document.documentElement.clientHeight;
  	}
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){//IE 4 compatible
    	pointer.w = document.body.clientWidth;
    	pointer.h = document.body.clientHeight;
  	}
	return pointer;
}